#include<iostream>
#include<climits>
const int N=2e5+10;
using namespace std;
typedef long long ll;
int nums[N];
int d[N];
int main()
{
	int n;cin>>n;
	for(int i=1;i<=n;i++)
	{
		int x;cin>>x;
		nums[i]=nums[i-1]+x;
		d[i]=min(nums[i],d[i-1]);
	}

	int ret=INT_MIN;
	for(int i=1;i<=n;i++)
	{
		ret=max(ret,nums[i]-d[i-1]);
	}
	cout<<ret<<endl;
}